//@ts-nocheck
import React, {useEffect, useState, useLayoutEffect, useRef} from 'react';

export default function(){
  const [n, setN] = useState('');

  const timer = useRef(null);

  const onClick = () => {
    setN(i => i + 1);
    timer.current = performance.now();
  };

  useEffect(() => {
    if (timer.current) {
      console.log('useEffect:',performance.now() - timer.current); // 单位是毫秒
    }
  });

  //执行时间相差1毫秒左右

  useLayoutEffect(() => {
    if (timer.current) {
      console.log('useLayoutEffect:',performance.now() - timer.current); // 单位是毫秒
    }
  });

  return (
    <>
      <div id="myDiv">{n}</div>
      <button onClick={onClick}>点击</button>
    </>
  )
}

